﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QLKDS.DTO;

namespace QLKDS.DAL
{
    public class ImportBookDetailManager
    {
        public IList<ImportBookDetail> ListImportBookDetail()
        {
            List<ImportBookDetail> listdata=new List<ImportBookDetail>();
            using (var db = new QLKDSDataContext())
            {
                listdata = db.ImportBookDetails.ToList();
                
            }
            return listdata;
        }
    

        public void CreateImportBookDetail(ImportBookDetail ImportBookDetail)
        {
            using (var db = new QLKDSDataContext())
            {
                db.ImportBookDetails.InsertOnSubmit(ImportBookDetail);

                db.SubmitChanges();
               
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="importBookDetail"></param>
        public void UpdateImportBookDetail(ImportBookDetail importBookDetail)
        {
            using (var db = new QLKDSDataContext())
            {
                var _importBookDetail = db.ImportBookDetails.Single(d => d.Id.Equals(importBookDetail.Id));
                _importBookDetail.BookId = importBookDetail.BookId;
                _importBookDetail.ImportId = importBookDetail.ImportId;
                _importBookDetail.Price = importBookDetail.Price;
                _importBookDetail.Quantity= importBookDetail.Quantity;
                _importBookDetail.DiscountPercent = importBookDetail.DiscountPercent;
                _importBookDetail.TotalPrice = importBookDetail.TotalPrice;
                _importBookDetail.StoreId = importBookDetail.StoreId;
                db.SubmitChanges();
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="id"></param>
        public void DeleteImportBookDetail(int id)
        {
            using (var db = new QLKDSDataContext())
            {
                var _ImportBookDetail = db.ImportBookDetails.Single(d => d.Id.Equals(id));

                db.ImportBookDetails.DeleteOnSubmit(_ImportBookDetail);
                db.SubmitChanges();
            }
        }



     
    }
}
